package ioc

import (
	article1 "bbs-web/internal/events/article"
	"github.com/IBM/sarama"
)

func InitSaramaClient(cfg *Config) sarama.Client {
	scfg := sarama.NewConfig()
	scfg.Producer.Return.Successes = true
	client, err := sarama.NewClient(cfg.KafkaCfg.Brokers, scfg)
	if err != nil {
		panic(err)
	}
	return client
}

func InitSyncProducer(c sarama.Client) sarama.SyncProducer {
	producer, err := sarama.NewSyncProducerFromClient(c)
	if err != nil {
		panic(err)
	}
	return producer
}

func InitConsumer(c article1.Consumer) []article1.Consumer {
	return []article1.Consumer{c}
}
